<?php
/**
 * XIE--Scorpion
 *
 * 网站配置
 * 
 */
namespace App\Models\Admin;

use DB,Session,Redirect;
use Illuminate\Database\Eloquent\Model;

class Config extends Model
{
    
    protected $table = 'config';
    public $timestamps = false;

    /*
     *友情链接
     */
    static function links()
    {
    	$links=DB::table('friendshiplink')->paginate(5);

    	return $links;

    }

    /*
     *友情链接 增 删 改 
     *
     * $a 处理的数据
     */
    static function linkDo($a)
    {
        $do=$a['do'];
        unset($a['do']);

        if($do=='in'){
            if(DB::table('friendshiplink')->insert($a)){

                return true;

            }else{

                return false;

            }
        }else if($do=='del'){
            $id=$a['friendlink_id'];
            if(DB::table('friendshiplink')->where('friendlink_id',$id)->delete()){

                return true;

            }else{

                return false;

            }    
        }else if($do=='save'){
            $id=$a['friendlink_id'];
            unset($a['friendlink_id']);
            if(DB::table('friendshiplink')->where('friendlink_id',$id)->update($a)){

                return true;

            }else{

                return false;

            }    
        }else{

            return false;
        }
    }

    /*
     *获得 覆盖城市
     */
    static function myRegion()
    {
        $list = DB::table('city')->get();

        return $list ;
    }
    
    /*
     *添加覆盖城市
     *
     * $arr 写入的数据
     */
    static function cityAdd($arr)
    {
        if(DB::table('city')->insert($arr)){
            return true;
        }else{
            return false;
        }
    }

    /*
     *
     */
    static function liandong($id)
    {
        $list = DB::table('region')->where('parent_id',$id)->get();

        foreach($list as $k=>$v){
            $arr[$k]=array(
                'region_id'=>$v->region_id,
                'region_name'=>$v->region_name,
                'region_type'=>$v->region_type,
                'parent_id'=>$v->parent_id,
                'agency_id'=>$v->agency_id
                );
        }

        return $arr;
    }
}